package com.gitee.wsl.ext.list

fun <T> MutableList<T>.push(item: T) = this.add(this.count(), item)

fun <T> MutableList<T>.popOrNull(): T? = if(this.isNotEmpty()) this.removeAt(this.count() - 1) else null

fun <T> MutableList<T>.pop(): T = if(this.isNotEmpty()) this.removeAt(this.count() - 1) else throw IndexOutOfBoundsException()

fun <T> MutableList<T>.pollOrNull() = popOrNull()

fun <T> MutableList<T>.poll():T = pollOrNull()?:throw IndexOutOfBoundsException()



inline fun <T> MutableList<T>.usePop(block: (T) -> Unit) = popOrNull()?.let(block)

fun <T> MutableList<T>.peekOrNull(): T? = if(this.isNotEmpty()) this[this.count() - 1] else null

fun <T> MutableList<T>.peek(): T = if(this.isNotEmpty()) this[this.count() - 1] else throw IndexOutOfBoundsException()

inline fun <T> MutableList<T>.usePeek(block: (T) -> Unit) = peekOrNull()?.let(block)


